<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/static/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
 <meta name="viewport" content="width=device-width" />
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
 <title>工资--考核规则</title>

 <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet" />
 <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet" />
 <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
 <script src="${ctxStatic}/layui/layui.all.js"  type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>

</head>

<body>
<div id="alertdiv" style="display: none;padding: 20px;">
        <label class="layui-form-label">规则修改</label>
        <div class="layui-input-inline">
            <input type="text" id="getNum" required  lay-verify="required" placeholder="请输入数据" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline">
            <select id="getType" style="height: 35px;">
                <option value="">请选择</option>
                <option value="1">/天</option>
                <option value="2">全扣除</option>
                <option value="3">扣除三分之一</option>
            </select>
        </div>
</div>

 <div class="currentnav"><span class="tiao"></span><span class="navtitle">考核规则管理</span></div>
<div class="tabregion">
 <div class="serchcontent">
     <div class="search">
         <table>
             <tr>
                 <td>
                     <input type="button" class="button" value="保存"  id="btnsave" />
                 </td>
             </tr>

         </table>
     </div>
 </div>

 <div class="content"　style="margin-top:10px">
         <table class="layui-table" lay-data="" lay-filter="uatmzpdsummarylist">
             <thead>
             <tr>
                 <th lay-data="{field:'moduleName', width:100,align:'center',style:'color: #FCFF04;'}">补贴类型</th>
                 <th lay-data="{field:'fullMoney', width:100,align:'center',edit: 'text',style:'color: #FCFF04;'}">补贴额度</th>
                 <th lay-data="{field:'yearVaca', width:100,align:'center',event: 'yearVaca',style:'color: #FCFF04;'}">年休假</th>
                 <th lay-data="{field:'familyVaca', width:100,align:'center',event: 'familyVaca',style:'color: #FCFF04;'}">探亲假</th>
                 <th lay-data="{field:'marryVaca', width:100,align:'center',event: 'marryVaca',style:'color: #FCFF04;'}">婚假</th>
                 <th lay-data="{field:'birthVaca', width:100,align:'center',event: 'birthVaca',style:'color: #FCFF04;'}">生育假</th>
                 <th lay-data="{field:'deathVaca', width:100,align:'center',event: 'deathVaca',style:'color: #FCFF04;'}">丧假</th>
                 <th lay-data="{field:'hurtVaca', width:100,align:'center',event: 'hurtVaca',style:'color: #FCFF04;'}">因公致伤</th>
                 <th lay-data="{field:'fallVaca', width:100,align:'center',event: 'fallVaca',style:'color: #FCFF04;'}">病假</th>
                 <th lay-data="{field:'matterVaca', width:100,align:'center',event: 'matterVaca',style:'color: #FCFF04;'}">事假</th>
                 <th lay-data="{field:'otherVaca', width:100,align:'center',event: 'otherVaca',style:'color: #FCFF04;'}">其他</th>
                 <th lay-data="{field:'laterDay', width:100,align:'center',event: 'laterDay',style:'color: #FCFF04;'}" >迟到</th>
                 <th lay-data="{field:'leaveEarlyDay', width:100,align:'center',event: 'leaveEarlyDay',style:'color: #FCFF04;'}">早退</th>
                 <th lay-data="{field:'lostDay', width:100,align:'center',event: 'lostDay',style:'color: #FCFF04;'}">旷工</th>
                 <th lay-data="{field:'study', width:100,align:'center',event: 'study',style:'color: #FCFF04;'}">脱产学习</th>
                 <th lay-data="{field:'remove', width:100,align:'center',event: 'remove',style:'color: #FCFF04;'}">借调</th>
             </tr>
             </thead>
         </table>
	 </div>
</div>

<script>
    layui.use('table', function(){
        var $ = layui.jquery
        var table = layui.table;

        table.init('uatmzpdsummarylist', {
            height : $(window).height() - 100
            ,url : 'get_assrule_list' // 数据接口
            ,page : false // 开启分页
            ,limit : 30
            ,id: 'uatmzpdsummary'
            ,method:"post"
            ,request:{
                type:'post'
            }
            ,where:{
                year: $("#year").val(),
                zzpdjg:$("#zzpdjg").val(),
                dymzpyjg:$("#dymzpyjg").val(),
                szdw:$("#szdw").val()
            }
            ,done: function(res, page, count){

                var dataarr=res.data;
                $("[data-field='begintime']").children().each(function(index){
                    if(index>0){
                        var text=$(this).text();
                        var begin=(new Date(text)).format("yyyy-MM-dd");
                        $(this).text(begin);
                    }
                })
                $("[data-field='endtime']").children().each(function(index){
                    if(index>0){
                        var text=$(this).text();
                        var begin=(new Date(text)).format("yyyy-MM-dd");
                        $(this).text(begin);
                    }
                })
                $("[data-field='year']").children().each(function(index){
                    if(index>0){
                        var text=$(this).text();
                        if(text=="0"){
                            $(this).text($("#year").val());
                        }

                    }
                })

            }


        });

        //监听单元格事件
        table.on('tool(uatmzpdsummarylist)', function(obj){
            var data = obj.data;
            var eventType = obj.event;
            commonLayer(eventType,obj);
            // if(obj.event === 'yearVaca'){
            //     commonLayer('yearVaca',obj);
            // }
        });

        function commonLayer(sign,obj){
            top.mylayui.open({
                type: 2,
                title: '指标添加',
                shadeClose: true,
                shade: 0.5, btn: ["确定"],
                area: ['435px', '340px'],
                content: 'payass/assessrule_pay_edit',
                yes: function (index, layero) {
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#getNum');
                    var selectForm = body.find('#getType');
                    var getnum = inputForm.val();
                    var gettype = selectForm.val();
                    var signrtn = '';
                    if (gettype == 1)
                        signrtn = getnum + "/天";
                    if (gettype == 2)
                        signrtn = "超" + getnum + "天金额全扣除";
                    if (gettype == 3)
                        signrtn = "超" + getnum + "天金额扣除三分之一";

                    // obj.update({sign: signrtn ,num : getnum,type : gettype });
                    switchUpate(sign, signrtn, getnum, gettype, obj)
                    top.mylayui.closeAll('iframe');

                }, success: function (layero, index) {
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#getNum');
                    var selectForm = body.find('#getType');

                    var data = obj.data;
                    var num = sign + 'Sum';
                    var type = sign + 'Type';
                    var value = data[num];
                    var select = data[type];
                    inputForm.val(value)
                    selectForm.val(select);
                }
            });
            var iframeele = top.$(".layui-layer-content").find('iframe');
            iframeele.css({"height": $(iframeele).height() - 10});
        }

        function switchUpate(sign,signrtn,getnum,gettype,obj){
            switch (sign)
            {
                case 'yearVaca':
                    obj.update({yearVaca: signrtn ,yearVacaSum : getnum,yearVacaType : gettype });
                    break;
                case 'familyVaca':
                    obj.update({familyVaca: signrtn ,familyVacaSum : getnum,familyVacaType : gettype });
                    break;
                case 'marryVaca':
                    obj.update({marryVaca: signrtn ,marryVacaSum : getnum,marryVacaType : gettype });
                    break;
                case 'birthVaca':
                    obj.update({birthVaca: signrtn ,birthVacaSum : getnum,birthVacaType : gettype });
                    break;
                case 'deathVaca':
                    obj.update({deathVaca: signrtn ,deathVacaSum : getnum,deathVacaType : gettype });
                    break;
                case 'hurtVaca':
                    obj.update({hurtVaca: signrtn ,hurtVacaSum : getnum,hurtVacaType : gettype });
                    break;
                case 'fallVaca':
                    obj.update({fallVaca: signrtn ,fallVacaSum : getnum,fallVacaType : gettype });
                    break;
                case 'matterVaca':
                    obj.update({matterVaca: signrtn ,matterVacaSum : getnum,matterVacaType : gettype });
                    break;
                case 'otherVaca':
                    obj.update({otherVaca: signrtn ,otherVacaSum : getnum,otherVacaType : gettype });
                    break;
                case 'laterDay':
                    obj.update({laterDay: signrtn ,laterDaySum : getnum,laterDayType : gettype });
                    break;
                case 'leaveEarlyDay':
                    obj.update({leaveEarlyDay: signrtn ,leaveEarlyDaySum : getnum,leaveEarlyDayType : gettype });
                    break;
                case 'lostDay':
                    obj.update({lostDay: signrtn ,lostDaySum : getnum,lostDayType : gettype });
                    break;
                case 'study':
                    obj.update({study: signrtn ,studySum : getnum,studyType : gettype });
                    break;
                case 'remove':
                    obj.update({remove: signrtn ,removeSum : getnum,removeType : gettype });
                    break;
            }
        }

        $("#btnsave").click(function(){
            var tabledataJson = JSON.stringify(table.cache);
            tabledataJson = tabledataJson.replace(/LAY_TABLE_INDEX/g,'lay_TABLE_INDEX');
            console.log(tabledataJson);

            $.ajax({
                type:"POST",
                url:"assessrule_pay_save",
                contentType: 'application/json',
                data:tabledataJson,
                beforeSend:function(XHR){

                },
                success:function(data){
                    data=eval('('+data+')');
                    if(data.result>0){
                        top.mylayui.msg(data.msg, {icon: 1});
                        document.location.reload();
                    }
                    else{
                        top.mylayui.msg(data.msg, {icon: 0});
                    }
                },
                complete:function(XHR){
                    var res = XHR.responseText;
                    CloseDialog(res)
                },
                error:function(XHR,errorText,errorType){
                    var res = XHR.responseText;
                    CloseDialog(res,errorText)
                }
            });
        })
    });

    function CloseDialog(result,msg){
        if(result>0){
            top.mylayui.msg('操作成功', {icon: 1});
            document.formedit.reset();
            document.location.reload();
        }
        else{
            if(msg){
                top.mylayui.msg(msg, {icon: 0});
            }else{
                top.mylayui.msg('操作失败', {icon: 0});
            }
        }
    }
</script>


</body>
</html>